home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / SWI / source / man / doc2tex (.txt) < prev    next >
Encoding:
LaTeX Document  |  1997-05-13  |  2.8 KB  |  118 lines

  1. #!/usr/local/bin/perl
  2. sub printTeX
  3. { s/`([@\w]+)\s*<->(\w+)/\\index{\l\1,\\both{\2}}`\1 \\both{\2}/g;
  4.   s/`([@\w]+)\s*<-(\w+)/\\index{\l\1,\\get{\2}}`\1 \\get{\2}/g;
  5.   s/`([@\w]+)\s*->(\w+)/\\index{\l\1,\\send{\2}}`\1 \\send{\2}/g;
  6.   s/<->(\w+)/\\both{\1}/g;
  7.   s/<-(\w+)/\\get{\1}/g;
  8.   s/->(\w+)/\\send{\1}/g;
  9.   s/([a-z]\w+)\/((\d+|\[\d+(-|,)\d+\]))/\\index{\l\1\/\2}\\predref{\l\1}{\2}/g;
  10.   s/(\w\.\w)\.(\s+[a-z])/\1.\\\2/g;
  11.   s/(^|[^\w}])@(\w+)/\1\\index{@\2}\\objectname{\2}/g;
  12.   s/<(\w[-~\w]*)>/\\bnfmeta{\1}/g;
  13.   s/\\class{([<\\=>]*)}/\\verb!\1!/g;
  14.   s/==>/\$\\longrightarrow\$/g;
  15.   s/(PL_\w+)\(([^)]*)\)/\\funcref{\1}{\2}/g;
  16.   s/^((\\index{[^}]+})+) *$/\1%/;
  17.   s/(\\file{[^}]*)~([^}]*})/\1\\Stilde\2/g;
  18.   s/(\\file{[^}]*)\$([^}]*})/\1\\Sdollar\2/g;
  19. # Prolog special arguments ...
  20.   s/{#!}/{\\Sexe}/g;
  21.   s/{!}/{\\Scut}/g;
  22.   s/{,}/{\\Scomma}/g;
  23.   s/{->}/{\\Sifthen}/g;
  24.   s/{\*->}/{\\Ssoftcut}/g;
  25.   s/{\.}/{\\Sdot}/g;
  26.   s/{;}/{\\Ssemicolon}/g;
  27.   s/{<}/{\\Slt}/g;
  28.   s/{=}/{\\Seq}/g;
  29.   s/{=\.\.}/{\\Suniv}/g;
  30.   s/{=:=}/{\\Saeq}/g;
  31.   s/{=<}/{\\Sle}/g;
  32.   s/{==}/{\\Sequal}/g;
  33.   s/{=@=}/{\\Sstructeq}/g;
  34.   s/{\\=@=}/{\\Sstructneq}/g;
  35.   s/{=\\=}/{\\Sane}/g;
  36.   s/{>}/{\\Sgt}/g;
  37.   s/{>=}/{\\Sge}/g;
  38.   s/{@<}/{\\Stlt}/g;
  39.   s/{@=<}/{\\Stle}/g;
  40.   s/{@>}/{\\Stgt}/g;
  41.   s/{@>=}/{\\Stge}/g;
  42.   s/{\\\+}/{\\Snot}/g;
  43.   s/{\\=}/{\\Sne}/g;
  44.   s/{\\==}/{\\Snequal}/g;
  45.   s/{\^}/{\\Shat}/g;
  46.   s/{\|}/{\\Sbar}/g;
  47.   s/{\*}/{\\Stimes}/g;
  48.   s/{\*\*}/{\\Spow}/g;
  49.   s/{\+}/{\\Splus}/g;
  50.   s/{-}/{\\Sminus}/g;
  51.   s/{\/}/{\\Sdiv}/g;
  52.   s/{\/\/}/{\\Sidiv}/g;
  53.   s/{\/\\}/{\\Sand}/g;
  54.   s/{<<}/{\\Slshift}/g;
  55.   s/{>>}/{\\Srshift}/g;
  56.   s/{\\}/{\\Sneg}/g;
  57.   s/{\\\/}/{\\Sor}/g;
  58.   s/{\$}/{\\Sdollar}/g;
  59.   s/{\?}/{\\Squest}/g;
  60.   s/{:}/{\\Smodule}/g;
  61.   s/{:-}/{\\Sneck}/g;
  62.   s/{\?-}/{\\Sdirective}/g;
  63.   s/{-->}/{\\Sdcg}/g;
  64.   s/{~}/{\\Stilde}/g;
  65.   s/{%}/{\\Spercent}/g;
  66.   print;
  67. sub expandTabs
  68. { while ( ($i = index($_, "\t")) != $[-1 )
  69.   { $nspaces = 8 - $i % 8;
  70.     for( $spaces="", $i=0; $i<$nspaces; $i++ )
  71.     { $spaces .= " ";
  72.     }
  73.     s/\t/$spaces/;
  74. expandSpecials
  75. { s/\^/\\verb!^!/g;
  76.   s/\|/\\verb!|!/g;
  77. sub printCode
  78. { print;
  79.   while (<ARGV> )
  80.   { &expandTabs;
  81.     print;
  82.     if ( /\\end{(code|verbatim)}/ )
  83.     { return;
  84.     }
  85. sub printPceCode
  86. { $line = 0;
  87.   print;
  88.   while (<ARGV> )
  89.   { $line++;
  90.     &expandTabs;
  91.     if ( /\\end{pcecode}/ )
  92.     { print;
  93.       return;
  94.     }
  95.     chomp;
  96.     print "\\lineno{$line}\\verb`$_`\n";
  97. sub skiptonext
  98. { while (<ARGV>)
  99.   { if ( ! /^\s*$/ )
  100.     { return;
  101.     }
  102.     last;
  103.   while (<ARGV>)
  104.   { if ( ! /^\s*$/ )
  105.     { return;
  106.     }
  107. #    MAIN PROGRAM
  108. while (<>)
  109. { while ( /\\begin{pcecode}/ )
  110.   { &printPceCode;
  111.     print "\n\\noindent\n";
  112.     &skiptonext;
  113.   while ( /\\begin{(code|verbatim)}/ )
  114.   { &printCode;
  115.     print "\n\\noindent\n";
  116.     &skiptonext;
  117.   &printTeX;
  118.